package br.ucb.teste;

import java.util.List;

import br.ucb.bean.Login;
import br.ucb.dao.LoginDAO;
import br.ucb.util.SimpleEntityManager;

public class TesteLoginDAO {

	public static void main(String[] args) {
		// cadastrarLogin();
		listarLogin();
	}

	private static void listarLogin() {
		SimpleEntityManager manager = new SimpleEntityManager("sacop");
		manager.beginTransaction();
		LoginDAO loginDAO = new LoginDAO(manager.getEntityManager());
		manager.close();
		List<Login> logins = loginDAO.listar();
		for (Login login : logins) {
			System.out.println(login.getUsuario());
			System.out.println(login.getSenha());
		}

	}

	private static void cadastrarLogin() {
		Login login = null;
		SimpleEntityManager manager = new SimpleEntityManager("sacop");
		LoginDAO loginDAO = new LoginDAO(manager.getEntityManager());

		String usuarios[] = { "Ana", "Karina", "Diego", "Klaus" };
		String senhas[] = { "aaaa", "bbbb", "cccc", "dddd" };

		for (int i = 0; i < 4; i++) {
			login = new Login();
			login.setUsuario(usuarios[i]);
			login.setSenha(senhas[i]);
			loginDAO.salvar(login);
		}

	}

}
